package com.kkui.liuxin.service;

import com.kkui.liuxin.mapper.SelectUsernameMp;
import com.kkui.liuxin.mapper.saveUserInfoMp;
import com.kkui.liuxin.pojo.User;
import com.kkui.liuxin.shiro_jwt.JwtUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author kkui
 * 调用用户相关数据接口
 */
@Service
public class UserService {
    @Resource
    SelectUsernameMp usernameMp;

    @Resource
    saveUserInfoMp saveUserInfoMp;


    public User getUserInfoByName(String username){
        //这里如果没查到返回的User对象为空
        return usernameMp.getUser(username);
    }

    public User getSaltByName(String username){
        return usernameMp.getSalt(username);
    }

    public User getPwd(String username){
        return usernameMp.getPwd(username);
    }


    public int setUserRegisterInfo(String name,String pwd,String salt){
        return saveUserInfoMp.saveRegister(name,pwd,salt);
    }

    /**
     * 通过jwt获取用户id
     * @param authorization
     * @return 用户id
     */
    public int jwtGetUserId(String authorization){
        return usernameMp.getUser(JwtUtil.getUsername(authorization)).getId();
    }

}
